function outside(fontSize, ifRounding, ifTagColorValue) {
  // 转换单位
  function pointToMM(numIn) {
    return (numIn / 72) * 25.4;
  }
  function MMTopoint(numIn) {
    return (numIn / 25.4) * 72;
  }
  // 格式化数字
  function formatNumForOutput(numIn) {
    return parseFloat(trimEndZero(formatNum(numIn, 2)));
  }
  if (documents.length > 0) {
    var activeDocument = app.activeDocument;
    var elementsSelected = activeDocument.selection;
    if (elementsSelected.length > 0) {
      // 文本框形式导入AI
      app.paste();
      // 获取文本
      var inputText = activeDocument.textFrames[0];
      var inputTextContent = inputText.contents;
      // 删除原始文本框
      inputText.remove();

      // 处理文本，分离色值
      var splitMark;
      if (inputTextContent.search(", ") != -1) {
        splitMark = ", ";
      } else if (inputTextContent.search(",") != -1) {
        splitMark = ",";
      } else if (inputTextContent.search("， ") != -1) {
        splitMark = "， ";
      } else if (inputTextContent.search("，") != -1) {
        splitMark = "，";
      } else if (inputTextContent.search("-") != -1) {
        splitMark = "-";
      } else if (inputTextContent.search(" ") != -1) {
        splitMark = " ";
      }
      var colorValue = inputTextContent.split(splitMark);
      // alert(colorValue[0] + "-" + colorValue[1] + "-" + colorValue[2] + "-" + colorValue[3]);
      // alert(colorValue.length);
      // 判断文本是RGB还是CMYK
      var InputColorMode;
      // RGB->0,CMYK->1
      if (colorValue.length > 3) {
        // CMYK
        InputColorMode = 1;
      } else {
        // 其他
        InputColorMode = 0;
      }

      for (i = 0; i < elementsSelected.length; i++) {
        var targetItem = elementsSelected[i];

        // 判断是否与文档颜色设置一致
        // 获取选中物体填充色
        var orginalColor = targetItem.fillColor;
        // 由文档的颜色模式决定颜色的哪些属性可以读取。比如CMYK才有cyan属性。
        // CMYK
        var colorC = orginalColor.cyan;
        var colorM = orginalColor.magenta;
        var colorY = orginalColor.yellow;
        var colorK = orginalColor.black;
        // RGB
        var colorR = orginalColor.red;
        var colorG = orginalColor.green;
        var colorB = orginalColor.blue;
        // 根据选中物体颜色，自动判断文档颜色模式
        var docColorMode;
        if (colorC == undefined) {
          docColorMode = 0;
        }
        if (colorR == undefined) {
          docColorMode = 1;
        }
        // 判断颜色模式是否一致
        if (InputColorMode != docColorMode) {
          alert(
            "复制的色值与当前文档的颜色模式不一致！\n请尝试复制一致的颜色！"
          );
        } else {
          //颜色模式一致
          // 用分离的色值创建新的颜色
          var newColorC, newColorM, newColorY, newColorK;
          var newColorR, newColorG, newColorB;
          switch (InputColorMode) {
            case 0:
              newColorR = parseInt(colorValue[0]);
              newColorG = parseInt(colorValue[1]);
              newColorB = parseInt(colorValue[2]);
              var newColor = new RGBColor();
              newColor.red = newColorR;
              newColor.green = newColorG;
              newColor.blue = newColorB;
              // 将新的颜色设置为选中物体的填充色
              targetItem.fillColor = newColor;
              break;
            case 1:
              newColorC = parseInt(colorValue[0]);
              newColorM = parseInt(colorValue[1]);
              newColorY = parseInt(colorValue[2]);
              newColorK = parseInt(colorValue[3]);
              var newColor = new CMYKColor();
              newColor.cyan = newColorC;
              newColor.magenta = newColorM;
              newColor.yellow = newColorY;
              newColor.black = newColorK;
              // 将新的颜色设置为选中物体的填充色
              targetItem.fillColor = newColor;
              break;
          }

          if (ifTagColorValue) {
            // 新建文本
            var outputText = targetItem.parent.textFrames.add();

            // 设置内容
            var textContent = "";
            switch (docColorMode) {
              case 0:
                textContent = newColorR + "-" + newColorG + "-" + newColorB;
                break;
              case 1:
                if (ifRounding) {
                  textContent =
                    newColorC.toFixed() +
                    "-" +
                    newColorM.toFixed() +
                    "-" +
                    newColorY.toFixed() +
                    "-" +
                    newColorK.toFixed();
                } else {
                  textContent =
                    formatNumForOutput(newColorC) +
                    "-" +
                    formatNumForOutput(newColorM) +
                    "-" +
                    formatNumForOutput(newColorY) +
                    "-" +
                    formatNumForOutput(newColorK);
                }
                break;
            }
            // 传递文本内容
            outputText.contents = textContent;
            // 设置字体大小
            outputText.textRange.characterAttributes.size = MMTopoint(fontSize);
            // 设置字体
            for (n = 0; n < app.textFonts.length; n++) {
              if (app.textFonts[n].name == "MicrosoftYaHei") {
                outputText.textRange.characterAttributes.textFont =
                  app.textFonts[n];
              }
            }
            // 设置文本坐标
            outputText.top =
              targetItem.top - targetItem.height - outputText.height / 2;
            outputText.left =
              targetItem.left + targetItem.width / 2 - outputText.width / 2;
          }

          // 重绘
          redraw();
        }
      }
      targetItem.selected = false;
    } else {
      alert("请先选中一个物体!");
    }
  } else {
    alert("请先打开一个文档!");
  }
}

function formatNum(numIn, accuracyIn) {
  var tempNum = numIn.toFixed(accuracyIn + 2).slice(0, -1);
  var tempNumString = "" + tempNum;
  var lastNum = parseInt(tempNumString.charAt(tempNumString.length - 1));
  if (lastNum != 0) {
    var zeroString = "";
    var tempString = "";
    for (k = 1; k < accuracyIn; k++) {
      zeroString += "0";
    }
    tempString = "0." + zeroString + "1";
    // 此时area为字符串
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
    numIn = parseFloat(numIn) + parseFloat(tempString);
  } else {
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
  }
  return numIn;
}

function trimEndZero(numIn) {
  var originString = "" + numIn;
  numIn = parseFloat(originString);
  return numIn;
}
